package com.example.demo.controller;

import com.example.demo.pojo.RoomReserve;
import com.example.demo.service.impl.RoomReserveServiceImpl;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
import io.swagger.annotations.Api;

import javax.annotation.Resource;

/**
 * (RoomReserve)表控制层
 *
 * @author makejava
 * @since 2025-01-19 21:37:57
 */
@RestController
@RequestMapping("roomReserve")
@Api(value = "(RoomReserve)", tags = "(RoomReserve)接口API")
public class RoomReserveController {
    /**
     * 服务对象
     */
    @Resource
    private RoomReserveServiceImpl roomReserveServiceImpl;

    /**
     * 一次性全部查询
     *
     * @return 查询结果
     */
    @GetMapping("/selectAll")
    public Map<String, Object> selectAll() {
        return roomReserveServiceImpl.selectAll();
    }

    /**
     * 分页查询
     *
     * @param roomReserve 筛选条件
     * @param page        要查询第几页
     * @param limit       每页显示多少条
     * @return 查询结果
     */
    @GetMapping("/selectByLimit")
    public Map<String, Object> selectByLimit(RoomReserve roomReserve, @RequestParam int page, @RequestParam int limit) {
        return roomReserveServiceImpl.selectByLimit(roomReserve, page, limit);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/selectById")
    public Map<String, Object> selectById(@RequestParam Integer id) {
        return roomReserveServiceImpl.selectById(id);
    }

    /**
     * 新增数据
     *
     * @param roomReserve 实体
     * @return 新增结果
     */
    @PostMapping("/insert")
    public Map<String, Object> insert(@RequestBody RoomReserve roomReserve) {
        return roomReserveServiceImpl.insert(roomReserve);
    }

    /**
     * 编辑数据
     *
     * @param roomReserve 实体
     * @return 编辑结果
     */
    @PutMapping("/updateById")
    public Map<String, Object> updateById(@RequestBody RoomReserve roomReserve) {
        return roomReserveServiceImpl.updateById(roomReserve);
    }

    /**
     * 删除数据
     *
     * @param reservationId 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/deleteById")
    public Map<String, Object> deleteById(@RequestParam Integer reservationId) {
        return roomReserveServiceImpl.deleteById(reservationId);
    }

    /**
     * 将记录添加到已入住房间订单
     *
     * @param roomReserve 实体
     * @return 添加结果
     */
    @PostMapping("/addToCheckinList")
    public Map<String, Object> addToCheckinList(@RequestBody RoomReserve roomReserve) {
        return roomReserveServiceImpl.addToCheckinList(roomReserve);
    }

    /**
     * 办理退房
     *
     * @param roomReserve 退房信息
     * @return 退房结果
     */
    @PostMapping("/checkOut")
    public Map<String, Object> checkOut(@RequestBody RoomReserve roomReserve) {
        Map<String, Object> result = roomReserveServiceImpl.checkOut(roomReserve);
        if (result.get("code").equals(200)) {
            result.put("msg", "退房成功");
        } else {
            result.put("msg", "退房失败");
        }
        return result;
    }
}